<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"><title>docker镜像仓库 | 如是的学习博客</title><meta name="keywords" content="docker"><meta name="author" content="rushiy"><meta name="copyright" content="rushiy"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="docker镜像仓库启动容器时，docker daemon会试图从本地获取相关镜像，本地镜像不存在时，其将从Registry中下载该镜像并保存到本地  Docker Registry分类： Registry用于保存docker镜像，包括镜像的层次结构和元数据，用户可自建Registry，也可以使用官方的Docker Hub仓库，分类如下：  Sponsor Registry：第三方仓库，供客户和d">
<meta property="og:type" content="article">
<meta property="og:title" content="docker镜像仓库">
<meta property="og:url" content="https://rushiy.gitee.io/docker/docker%E9%95%9C%E5%83%8F%E4%BB%93%E5%BA%93/index.html">
<meta property="og:site_name" content="如是的学习博客">
<meta property="og:description" content="docker镜像仓库启动容器时，docker daemon会试图从本地获取相关镜像，本地镜像不存在时，其将从Registry中下载该镜像并保存到本地  Docker Registry分类： Registry用于保存docker镜像，包括镜像的层次结构和元数据，用户可自建Registry，也可以使用官方的Docker Hub仓库，分类如下：  Sponsor Registry：第三方仓库，供客户和d">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2022-09-24T10:27:35.000Z">
<meta property="article:author" content="rushiy">
<meta property="article:tag" content="docker">
<meta name="twitter:card" content="summary"><link rel="shortcut icon" href="/img/favicon.jpg"><link rel="canonical" href="https://rushiy.gitee.io/docker/docker%E9%95%9C%E5%83%8F%E4%BB%93%E5%BA%93/"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.min.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = { 
  root: '/',
  algolia: undefined,
  localSearch: undefined,
  translate: undefined,
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '',
  date_suffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: undefined,
  source: {
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.css'
    }
  },
  isPhotoFigcaption: false,
  islazyload: false,
  isAnchor: false
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: 'docker镜像仓库',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2022-11-19 01:18:40'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
    const detectApple = () => {
      if(/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
        document.documentElement.classList.add('apple')
      }
    }
    detectApple()
    })(window)</script><meta name="generator" content="Hexo 6.3.0"></head><body><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src="/img/favicon.jpg" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="sidebar-site-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">28</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">3</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">0</div></a></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url('')"><nav id="nav"><span id="blog_name"><a id="site-name" href="/">如是的学习博客</a></span><div id="menus"><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div><div id="toggle-menu"><a class="site-page"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">docker镜像仓库</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2022-09-24T10:27:35.000Z" title="发表于 2022-09-24 18:27:35">2022-09-24</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2022-11-18T17:18:40.845Z" title="更新于 2022-11-19 01:18:40">2022-11-19</time></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="docker镜像仓库"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"><i class="fa-solid fa-spinner fa-spin"></i></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><h2 id="docker镜像仓库"><a href="#docker镜像仓库" class="headerlink" title="docker镜像仓库"></a>docker镜像仓库</h2><p>启动容器时，docker daemon会试图从本地获取相关镜像，本地镜像不存在时，其将从Registry中下载该镜像并保存到本地</p>
<p><img src="/pic/docker-pic/clip_image056.jpg" alt="img"></p>
<p><strong>Docker Registry分类：</strong></p>
<p>Registry用于保存docker镜像，包括镜像的层次结构和元数据，用户可自建Registry，也可以使用官方的Docker Hub仓库，分类如下：</p>
<ul>
<li><p>Sponsor Registry：第三方仓库，供客户和docker社区使用</p>
</li>
<li><p>Mirror Registry：第三方仓库，只供客户使用</p>
</li>
<li><p>Vendor Registry：由发布docker镜像的供应商提供的Registry</p>
</li>
<li><p>Private Registry：通过设有防火墙和额外的安全层的私有实体提供的Registry，如VMware的harbor</p>
</li>
</ul>
<p><strong>Docker Registry的构成</strong></p>
<ul>
<li><p>Repository</p>
<ul>
<li>由特定的docker镜像的所有迭代版本组成的镜像仓库，一个Registry中包含多个Repository</li>
<li>Repository可分为“顶级仓库”和“用户仓库“，用户仓库的格式为“用户名&#x2F;仓库名”</li>
<li>每个镜像可以包含多个Tag(标签)，每个镜像内的Tag唯一</li>
</ul>
</li>
<li><p>Index</p>
<ul>
<li>维护用户账号、镜像的校验已经公共命名空间的信息</li>
<li>相当于为Registry提供了一个完成用户认证等功能的索引接口</li>
</ul>
</li>
</ul>
<p>​		Docker Registry中的镜像通常由开发人员制作（一般是基于基础镜像制作，基础镜像由专业人士制作，如docker官方人员），而后推送至“公共”或“私有”Registry上保存，供其他人员使用，例如“部署”到生产环境中。</p>
<p><img src="/pic/docker-pic/clip_image058.jpg" alt="img"></p>
<p>镜像的生成途径：</p>
<ul>
<li><p>Dockerfile</p>
</li>
<li><p>基于容器制作</p>
</li>
<li><p>Docker Hub automated builds</p>
</li>
</ul>
<p><img src="/pic/docker-pic/clip_image060.jpg" alt="img"></p>
<h3 id="制作本地镜像仓库"><a href="#制作本地镜像仓库" class="headerlink" title="制作本地镜像仓库"></a>制作本地镜像仓库</h3><ul>
<li>拉取并启动registry</li>
</ul>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">docker image <span class="built_in">ls</span> | grep registry</span></span><br><span class="line">registry     latest     2d4f4b5309b1   4 weeks ago   26.2MB</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">启动该镜像容器，--restart=always表示无论时服务器重启或者是docker服务重启之后都自动重启该容器，即该容器会自启</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">docker run -d -p 5000:5000 --restart=always --name registry -v /opt/registry:/var/lib/registry registry</span></span><br><span class="line">07da1db7effae881bc22570542efc2065a98d863e08b0a109e71087a9c9615ac</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">设置仓库地址为本机地址，默认是docker hub，这里设置成本机(刚刚启动的容器)</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">vim /etc/docker/daemon.json   <span class="comment"># 注意格式，多行内容以逗号结尾，json格式</span></span></span><br><span class="line">&#123;</span><br><span class="line">    &quot;registry-mirrors&quot;: [&quot;https://registry.docker-cn.com&quot;,&quot;http://hub-mirror.c.163.com&quot;],  </span><br><span class="line">    &quot;insecure-registries&quot;: [&quot;10.138.3.15:5000&quot;] # 最后一行无逗号</span><br><span class="line">&#125;</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">重启docker，重读配置文件</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">systemctl restart docker</span> </span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">检查容器，发现也自动重启了</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">docker container <span class="built_in">ls</span></span></span><br><span class="line">CONTAINER ID  IMAGE       COMMAND              CREATED      STATUS          PORTS               NAMES</span><br><span class="line">07da1db7effa registry &quot;/entrypoint.sh /etc…&quot;  4 minutes ago Up 9 seconds 0.0.0.0:5000-&gt;5000/tcp registry</span><br></pre></td></tr></table></figure>

<ul>
<li>修改镜像标签并推送到registry</li>
</ul>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">重新给镜像打标签</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">docker image tag 5259a77d042b 10.138.3.15:5000/scaven/centos6_bbs:v1</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">docker image <span class="built_in">ls</span> | grep 10.138</span></span><br><span class="line">10.138.3.15:5000/scaven/centos6_bbs v1 5259a77d042b  17 hours ago 477MB</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">上传镜像</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">docker image <span class="built_in">ls</span> | grep 10.138</span></span><br><span class="line">10.138.3.15:5000/scaven/centos6_bbs   v1     5259a77d042b        17 hours ago     477MB</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">docker push 10.138.3.15:5000/scaven/centos6_bbs:v1</span></span><br><span class="line">The push refers to repository [10.138.3.15:5000/scaven/centos6_bbs]</span><br><span class="line">8028f132d224: Pushed </span><br><span class="line">b01adbd9e75d: Pushed </span><br><span class="line">8088cb617267: Pushed </span><br><span class="line">v1: digest: sha256:57b830b668ca8de9f1eca19ecd1d84d9ca1892dbed4c67a10306ae9e556166e4 size: 950</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">查看宿主机上目录映射中的文件</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash"><span class="built_in">ls</span> /opt/registry/</span></span><br><span class="line">docker</span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash"><span class="built_in">ls</span> /opt/registry/docker/registry/</span></span><br><span class="line">v2</span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash"><span class="built_in">ls</span> /opt/registry/docker/registry/v2/</span></span><br><span class="line">blobs  repositories</span><br></pre></td></tr></table></figure>

<ul>
<li>测试拉取镜像</li>
</ul>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">测试，删除本机上的10.138.3.15:5000/scaven/centos6_bbs:v1镜像，然后从仓库中下载，先做备份再删除</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">docker  image save -o registry_bbs.tar  5259a77d042b</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">docker image <span class="built_in">rm</span>  -f 5259a77d042b   <span class="comment"># 删除</span></span></span><br><span class="line">Untagged: 10.138.3.15:5000/scaven/centos6_bbs:v1</span><br><span class="line">Untagged: 10.138.3.15:5000/scaven/centos6_bbs@sha256:57b830b668ca8de9f1eca19ecd1d84d9ca1892dbed4c67a10306ae9e556166e4</span><br><span class="line">Untagged: scaven/centos6_bbs:v1</span><br><span class="line">Deleted: sha256:5259a77d042b9f0a2ca73f385603733d025b22c1ce3e549e1c25f95cd7c8bdcb</span><br><span class="line">Deleted: sha256:aa0085e1bee996bbffafae209a85ad2e7ee3e767cf43c9117728b761341efcc0</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">docker image <span class="built_in">ls</span> | grep 5259a77d042b  <span class="comment"># 已删除成功</span></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash"></span></span><br><span class="line"><span class="language-bash"></span><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">重新下载5259a77d042b镜像</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">docker pull 10.138.3.15:5000/scaven/centos6_bbs:v1</span></span><br><span class="line">v1: Pulling from scaven/centos6_bbs</span><br><span class="line">06a11a3d840d: Already exists </span><br><span class="line">0bc80ff48944: Already exists </span><br><span class="line">c33df8f494cd: Pull complete </span><br><span class="line">Digest: sha256:57b830b668ca8de9f1eca19ecd1d84d9ca1892dbed4c67a10306ae9e556166e4</span><br><span class="line">Status: Downloaded newer image for 10.138.3.15:5000/scaven/centos6_bbs:v1</span><br><span class="line">10.138.3.15:5000/scaven/centos6_bbs:v1</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">docker image <span class="built_in">ls</span> | grep 5259a77d042b</span></span><br><span class="line">10.138.3.15:5000/scaven/centos6_bbs v1 5259a77d042b 17 hours ago 477MB</span><br></pre></td></tr></table></figure>

<h3 id="本地镜像仓库加密"><a href="#本地镜像仓库加密" class="headerlink" title="本地镜像仓库加密"></a>本地镜像仓库加密</h3><p>上文章节中的实现了镜像仓库的功能，但是任何人都能访问和上传镜像到仓库中，是十分不安全的，因此，我们应该给镜像仓库做加密，只有有密码的用户才能进行访问仓库。</p>
<ul>
<li>生成加密文件</li>
</ul>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">删除前一个示例中启动的仓库镜像</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">docker container stop 07da1db7effa</span></span><br><span class="line">07da1db7effa</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">使用http-tools工具生成密钥文件</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">yum -y install httpd-tools</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash"><span class="built_in">mkdir</span> /opt/registry-auth</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">htpasswd  -Bbn scaven 123456 &gt; /opt/registry-auth/htpasswd</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash"><span class="built_in">cat</span> /opt/registry-auth/htpasswd</span> </span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">用户名：加密后的密码</span></span><br><span class="line">scaven:$2y$05$LAE/znxZd6RAXVgNrP6rJ.T5wv/JnmWL2D2QYfdUcCT9KSJfJKepS</span><br></pre></td></tr></table></figure>

<ul>
<li>启动镜像，指定密钥文件路径</li>
</ul>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">docker run -d -p 5000:5000 -v /opt/registry-auth/:/auth/ -v /opt/registry:/var/lib/registry --name registry-auth -e <span class="string">&quot;REGISTRY_AUTH=htpasswd&quot;</span> -e <span class="string">&quot;REGISTRY_AUTH_HTPASSWD_REALM=Regisry Realm&quot;</span> -e <span class="string">&quot;REGISTRY_AUTH_HTPASSWD_PATH=/auth/htpasswd&quot;</span> 2d4f4b5309b1</span></span><br><span class="line">c39b88dd0d44dc77529cb697a962c973e1543bf431270d222284cb2605701501</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">docker container <span class="built_in">ls</span></span></span><br><span class="line">CONTAINER ID   IMAGE   COMMAND    CREATED    STATUS   PORTS   NAMES</span><br><span class="line">c39b88dd0d44   2d4f4b5309b1 &quot;/entrypoint.sh /etc…&quot;   8 seconds ago       Up 7 seconds  0.0.0.0:5000-&gt;5000/tcp registry-auth</span><br></pre></td></tr></table></figure>

<ul>
<li>不登陆推送镜像到加密仓库会直接报错</li>
</ul>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">docker pull 10.138.3.15:5000/scaven/centos6_bbs:v1</span></span><br><span class="line">Error response from daemon: Get http://10.138.3.15:5000/v2/scaven/centos6_bbs/manifests/v1: no basic auth credential</span><br></pre></td></tr></table></figure>

<ul>
<li>登陆推送镜像到加密仓库</li>
</ul>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">使用用户名和密码登录，登录后再推送镜像</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">docker login 10.138.3.15:5000</span></span><br><span class="line">Username: scaven</span><br><span class="line">Password: </span><br><span class="line">WARNING! Your password will be stored unencrypted in /root/.docker/config.json.</span><br><span class="line">Configure a credential helper to remove this warning. See</span><br><span class="line">https://docs.docker.com/engine/reference/commandline/login/#credentials-store</span><br><span class="line"></span><br><span class="line">Login Succeeded</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">docker pull 10.138.3.15:5000/scaven/centos6_bbs:v1</span></span><br><span class="line">v1: Pulling from scaven/centos6_bbs</span><br><span class="line">Digest: sha256:57b830b668ca8de9f1eca19ecd1d84d9ca1892dbed4c67a10306ae9e556166e4</span><br><span class="line">Status: Image is up to date for 10.138.3.15:5000/scaven/centos6_bbs:v1</span><br><span class="line">10.138.3.15:5000/scaven/centos6_bbs:v1</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<ul>
<li>验证，删除本地镜像，重新从加密仓库拉取镜像</li>
</ul>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">删除本地镜像进行下载验证</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">docker image <span class="built_in">ls</span> | grep 10.138.3.15:5000/scaven/centos6_bbs</span></span><br><span class="line">10.138.3.15:5000/scaven/centos6_bbs v15259a77d042b  18 hours ago 477MB</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">docker image <span class="built_in">rm</span> -f 10.138.3.15:5000/scaven/centos6_bbs:v1  <span class="comment"># 从本地服务器上删除指定镜像</span></span></span><br><span class="line">Untagged: 10.138.3.15:5000/scaven/centos6_bbs:v1</span><br><span class="line">Untagged: 10.138.3.15:5000/scaven/centos6_bbs@sha256:57b830b668ca8de9f1eca19ecd1d84d9ca1892dbed4c67a10306ae9e556166e4</span><br><span class="line">Deleted: sha256:5259a77d042b9f0a2ca73f385603733d025b22c1ce3e549e1c25f95cd7c8bdcb</span><br><span class="line">Deleted: sha256:aa0085e1bee996bbffafae209a85ad2e7ee3e767cf43c9117728b761341efcc0</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">从10.138.3.15:5000中下载镜像</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">docker pull 10.138.3.15:5000/scaven/centos6_bbs:v1</span></span><br><span class="line">v1: Pulling from scaven/centos6_bbs</span><br><span class="line">06a11a3d840d: Already exists </span><br><span class="line">0bc80ff48944: Already exists </span><br><span class="line">c33df8f494cd: Pull complete </span><br><span class="line">Digest: sha256:57b830b668ca8de9f1eca19ecd1d84d9ca1892dbed4c67a10306ae9e556166e4</span><br><span class="line">Status: Downloaded newer image for 10.138.3.15:5000/scaven/centos6_bbs:v1</span><br><span class="line">10.138.3.15:5000/scaven/centos6_bbs:v1</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">docker image <span class="built_in">ls</span> | grep 10.138.3.15:5000/scaven/centos6_bbs  <span class="comment"># 下载成功</span></span></span><br><span class="line">10.138.3.15:5000/scaven/centos6_bbs v1 5259a77d042b  18 hours ago 477MB</span><br></pre></td></tr></table></figure>

<h2 id="私有仓库harbor"><a href="#私有仓库harbor" class="headerlink" title="私有仓库harbor"></a>私有仓库harbor</h2><h3 id="harbor简介"><a href="#harbor简介" class="headerlink" title="harbor简介"></a>harbor简介</h3><p><code>Harbor</code>是由<code>VMware公司</code>开源的一个用于<code>存储和分发Docker镜像的企业级docker镜像仓库</code>，默认使用<code>https</code>访问协议。通过添加一些企业必需的功能特性，例如安全、标识和管理等，扩展了开源<code>Docker Distribution</code>。作为一个企业级私有<code>Registry</code>服务器，<code>Harbor</code>提供了更好的性能和安全。提升用户使用<code>Registry</code>构建和运行环境传输镜像的效率。<code>Harbor</code>支持安装在多个<code>Registry</code>节点的镜像资源复制，镜像全部保存在私有<code>Registry</code>中， 确保数据和知识产权在公司内部网络中管控。另外，<code>Harbor</code>也提供了高级的安全特性，诸如用户管理，访问控制和活动审计等。</p>
<ol>
<li><code>云本机注册表</code>：Harbour 支持容器映像和Helm图表，可用作云本机环境（如容器运行时和业务流程平台）的注册表。</li>
<li><code>基于角色的访问控制</code>：用户和存储库通过“项目”进行组织，用户可以对项目下的镜像拥有不同的权限。</li>
<li><code>基于策略的镜像复制</code>：可以基于具有多个过滤器（存储库，标记和标签）的策略在多个注册表实例之间复制（同步）映像。如果遇到任何错误，Harbor将自动重试进行复制。非常适合负载平衡，高可用性，多数据中心，混合和多云场景。</li>
<li><code>漏洞扫描</code>：Harbor定期扫描镜像并警告用户漏洞。</li>
<li><code>LDAP/AD支持</code>：Harbor与现有企业LDAP &#x2F; AD集成以进行用户身份验证和管理，并支持将LDAP组导入Harbor并为其分配适当的项目角色。</li>
<li><code>镜像删除和垃圾收集</code>：可以删除镜像，并可以回收它们的空间。</li>
<li><code>公证</code>：可以确保镜像的真实性。</li>
<li><code>图形用户门户</code>：用户可以轻松浏览，搜索存储库和管理项目。</li>
<li><code>审计</code>：跟踪存储库的所有操作。</li>
<li><code>RESTful API</code>：适用于大多数管理操作的RESTful API，易于与外部系统集成。</li>
<li><code>易于部署</code>：提供在线和离线安装程序。</li>
</ol>
<p>　</p>
<p>官方文档：<a target="_blank" rel="noopener" href="https://goharbor.io/docs/">https://goharbor.io/docs/</a><br>github用户手册：<a target="_blank" rel="noopener" href="https://github.com/goharbor/harbor/blob/master/docs/user_guide.md">https://github.com/goharbor/harbor/blob/master/docs/user_guide.md</a><br>官网：<a target="_blank" rel="noopener" href="https://harbor.com/">https://harbor.com/</a></p>
<h3 id="harbor组件："><a href="#harbor组件：" class="headerlink" title="harbor组件："></a>harbor组件：</h3><table>
<thead>
<tr>
<th>组件</th>
<th align="left">功能</th>
</tr>
</thead>
<tbody><tr>
<td>harbor-adminserver</td>
<td align="left">配置管理中心</td>
</tr>
<tr>
<td>harbor-db</td>
<td align="left">Mysql数据库</td>
</tr>
<tr>
<td>harbor-jobservice</td>
<td align="left">负责镜像复制</td>
</tr>
<tr>
<td>harbor-log</td>
<td align="left">记录操作日志</td>
</tr>
<tr>
<td>harbor-ui</td>
<td align="left">Web管理页面和API</td>
</tr>
<tr>
<td>nginx</td>
<td align="left">前端代理，负责前端页面和镜像上传&#x2F;下载转发</td>
</tr>
<tr>
<td>redis</td>
<td align="left">会话</td>
</tr>
<tr>
<td>registry</td>
<td align="left">镜像存储</td>
</tr>
</tbody></table>
<h3 id="harbor下载与安装"><a href="#harbor下载与安装" class="headerlink" title="harbor下载与安装"></a>harbor下载与安装</h3><h4 id="harbor下载"><a href="#harbor下载" class="headerlink" title="harbor下载"></a>harbor下载</h4><p>服务器配置要求：2C&#x2F;4G&#x2F;40G，推荐4C&#x2F;8G&#x2F;160G</p>
<p>下载地址：<a target="_blank" rel="noopener" href="https://github.com/goharbor/harbor/releases">https://github.com/goharbor/harbor/releases</a></p>
<h4 id="安装方式"><a href="#安装方式" class="headerlink" title="安装方式"></a>安装方式</h4><ul>
<li>离线安装：下载harbor软件包到本地进行安装，软件包较大，下载速度慢</li>
<li>在线安装：</li>
<li>OVA安装程序：当用户具有vCenter环境时，使用此安装程序，在部署OVA后启动Harbor。</li>
</ul>
<p><img src="/pic/docker-pic/harbor_download.png" alt="image-20210405111645490"></p>
<h3 id="harbor安装"><a href="#harbor安装" class="headerlink" title="harbor安装"></a>harbor安装</h3><h4 id="安装docker"><a href="#安装docker" class="headerlink" title="安装docker"></a>安装docker</h4><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">如果已经安装了docker，可以使用下面的命令卸载</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">yum remove docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate docker-logrotate docker-engine</span> </span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">安装必要的依赖包</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">yum install -y device-mapper-persistent-data lvm2</span></span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">添加docker仓库，并修改成国内清华镜像源</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">wget -O /etc/yum.repos.d/docker-ce.repo https://download.docker.com/linux/centos/docker-ce.repo</span> </span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">sed -i <span class="string">&#x27;s#download.docker.com#mirrors.tuna.tsinghua.edu.cn/docker-ce#&#x27;</span> /etc/yum.repos.d/docker-ce.repo</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">yum clean all &amp;&amp; yum repolist</span></span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">安装docker</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">yum -y install docker-ce</span></span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">添加镜像加速器</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash"><span class="built_in">mkdir</span> /etc/docker</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">vim /etc/docker/daemon.json</span></span><br><span class="line">&#123;</span><br><span class="line">    &quot;registry-mirrors&quot;: [&quot;https://registry.docker-cn.com&quot;,&quot;http://hub-mirror.c.163.com&quot;]</span><br><span class="line">&#125;</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">启动并添加到开机自启动</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">systemctl start docker  &amp;&amp; systemctl <span class="built_in">enable</span> docker</span></span><br></pre></td></tr></table></figure>

<h4 id="安装docker-compose"><a href="#安装docker-compose" class="headerlink" title="安装docker-compose"></a>安装docker-compose</h4><p>harbor使用docker-compose进行编排，因此在安装harbor之前必须先安装docker-compose。</p>
<p>下载地址：<a target="_blank" rel="noopener" href="https://github.com/docker/compose/releases">https://github.com/docker/compose/releases</a></p>
<p><img src="/pic/docker-pic/image-20221024185559647.png" alt="image-20221024185559647"></p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash"><span class="built_in">ls</span> docker-compose-Linux-x86_64</span></span><br><span class="line">docker-compose-Linux-x86_64</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">添加执行权限并移动到环境变量路径中</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash"><span class="built_in">chmod</span> u+x docker-compose-Linux-x86_64</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash"><span class="built_in">mv</span> docker-compose-Linux-x86_64 /usr/bin/docker-compose</span> </span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">验证</span>  </span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">docker-compose  --version</span></span><br><span class="line">docker-compose version 1.28.6, build 5db8d86f</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">docker-compose简单用法</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">docker-compose --<span class="built_in">help</span></span></span><br><span class="line">Define and run multi-container applications with Docker.</span><br><span class="line"></span><br><span class="line">Usage:</span><br><span class="line">  docker-compose [-f &lt;arg&gt;...] [--profile &lt;name&gt;...] [options] [--] [COMMAND] [ARGS...]</span><br><span class="line">  docker-compose -h|--help</span><br><span class="line"></span><br><span class="line">Options:</span><br><span class="line">  -f, --file FILE             Specify an alternate compose file</span><br><span class="line">                              (default: docker-compose.yml)</span><br><span class="line">  -p, --project-name NAME     Specify an alternate project name</span><br><span class="line">                              (default: directory name)</span><br><span class="line">  --profile NAME              Specify a profile to enable</span><br><span class="line">  -c, --context NAME          Specify a context name</span><br><span class="line">  --verbose                   Show more output</span><br><span class="line">  --log-level LEVEL           Set log level (DEBUG, INFO, WARNING, ERROR, CRITICAL)</span><br><span class="line">  --ansi (never|always|auto)  Control when to print ANSI control characters</span><br><span class="line">  --no-ansi                   Do not print ANSI control characters (DEPRECATED)</span><br><span class="line">  -v, --version               Print version and exit</span><br><span class="line">  -H, --host HOST             Daemon socket to connect to</span><br><span class="line"></span><br><span class="line">  --tls                       Use TLS; implied by --tlsverify</span><br><span class="line">  --tlscacert CA_PATH         Trust certs signed only by this CA</span><br><span class="line">  --tlscert CLIENT_CERT_PATH  Path to TLS certificate file</span><br><span class="line">  --tlskey TLS_KEY_PATH       Path to TLS key file</span><br><span class="line">  --tlsverify                 Use TLS and verify the remote</span><br><span class="line">  --skip-hostname-check       Don&#x27;t check the daemon&#x27;s hostname against the</span><br><span class="line">                              name specified in the client certificate</span><br><span class="line">  --project-directory PATH    Specify an alternate working directory</span><br><span class="line">                              (default: the path of the Compose file)</span><br><span class="line">  --compatibility             If set, Compose will attempt to convert keys</span><br><span class="line">                              in v3 files to their non-Swarm equivalent (DEPRECATED)</span><br><span class="line">  --env-file PATH             Specify an alternate environment file</span><br><span class="line"></span><br><span class="line">Commands:</span><br><span class="line">  build              Build or rebuild services   # 构建或者重构服务</span><br><span class="line">  config             Validate and view the Compose file</span><br><span class="line">  create             Create services   # 创建服务</span><br><span class="line">  down               Stop and remove resources  # 停止运行中的容器</span><br><span class="line">  events             Receive real time events from containers</span><br><span class="line">  exec               Execute a command in a running container  # 进入一个运行的容器中</span><br><span class="line">  help               Get help on a command</span><br><span class="line">  images             List images   # 列出存在的所有镜像</span><br><span class="line">  kill               Kill containers   # kill掉容器</span><br><span class="line">  logs               View output from containers  # 查看容器日志输出</span><br><span class="line">  pause              Pause services   # 暂停服务</span><br><span class="line">  port               Print the public port for a port binding  # 列出端口</span><br><span class="line">  ps                 List containers   # 列出运行中的容器</span><br><span class="line">  pull               Pull service images  # 推镜像到仓库</span><br><span class="line">  push               Push service images  # 从仓库中拉取镜像</span><br><span class="line">  restart            Restart services     # 重启服务</span><br><span class="line">  rm                 Remove stopped containers  # 删除停止的容器</span><br><span class="line">  run                Run a one-off command</span><br><span class="line">  scale              Set number of containers for a service</span><br><span class="line">  start              Start services    # 启动服务</span><br><span class="line">  stop               Stop services     # 停止服务</span><br><span class="line">  top                Display the running processes  # 展示运行容器使用的资源信息</span><br><span class="line">  unpause            Unpause services</span><br><span class="line">  up                 Create and start containers    # 启动容器</span><br><span class="line">  version            Show version information and quit  # 查看docker-compose版本信息</span><br></pre></td></tr></table></figure>

<h4 id="安装harbor"><a href="#安装harbor" class="headerlink" title="安装harbor"></a>安装harbor</h4><p>harbor默认使用https协议进行访问，也支持http协议。因此接下来的安装过程将分成两个步骤，使用http协议和https协议进行harbor安装。</p>
<h5 id="解压并认识harbor配置文件"><a href="#解压并认识harbor配置文件" class="headerlink" title="解压并认识harbor配置文件"></a>解压并认识harbor配置文件</h5><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash"><span class="built_in">ls</span></span> </span><br><span class="line">harbor-offline-installer-v2.2.1.tgz</span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">tar zxvf harbor-offline-installer-v2.2.1.tgz    <span class="comment"># 解压</span></span></span><br><span class="line">harbor/harbor.v2.2.1.tar.gz</span><br><span class="line">harbor/prepare</span><br><span class="line">harbor/LICENSE</span><br><span class="line">harbor/install.sh</span><br><span class="line">harbor/common.sh</span><br><span class="line">harbor/harbor.yml.tmpl   # 配置文件样本</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash"><span class="built_in">cat</span> harbor.yml.tmpl  | grep -Ev <span class="string">&quot;^$|#&quot;</span>  <span class="comment"># 简单认识配置模板文件</span></span></span><br><span class="line">hostname: reg.mydomain.com   # 默认的域名，使用该域名需要域名解析，如果不做域名解析，可修改成harbor主机IP地址</span><br><span class="line">http:               # http信息，默认端口信息都可以自行修改</span><br><span class="line">  port: 80   </span><br><span class="line">https:              # https的端口和证书存放路径，默认使用Https协议，但使用https需要配置证书，若不使用可注释掉</span><br><span class="line">  port: 443    </span><br><span class="line">  certificate: /your/certificate/path</span><br><span class="line">  private_key: /your/private/key/path</span><br><span class="line">harbor_admin_password: Harbor12345   # 登陆harbor仓库web界面默认密码，默认用户为adamin，建议修改</span><br><span class="line">database:               # 数据库信息</span><br><span class="line">  password: root123     # 数据库root用户密码，建议修改</span><br><span class="line">  max_idle_conns: 50</span><br><span class="line">  max_open_conns: 1000</span><br><span class="line">data_volume: /data     # 默认存储位置</span><br><span class="line">trivy:</span><br><span class="line">  ignore_unfixed: false</span><br><span class="line">  skip_update: false</span><br><span class="line">  insecure: false</span><br><span class="line">jobservice:</span><br><span class="line">  max_job_workers: 10</span><br><span class="line">notification:</span><br><span class="line">  webhook_job_max_retry: 10</span><br><span class="line">chart:</span><br><span class="line">  absolute_url: disabled</span><br><span class="line">log:</span><br><span class="line">  level: info</span><br><span class="line">  local:</span><br><span class="line">    rotate_count: 50</span><br><span class="line">    rotate_size: 200M</span><br><span class="line">    location: /var/log/harbor</span><br><span class="line">_version: 2.2.0</span><br><span class="line">proxy:</span><br><span class="line">  http_proxy:</span><br><span class="line">  https_proxy:</span><br><span class="line">  no_proxy:</span><br><span class="line">  components:</span><br><span class="line">    - core</span><br><span class="line">    - jobservice</span><br><span class="line">    - trivy</span><br></pre></td></tr></table></figure>

<h5 id="使用http协议访问harbor"><a href="#使用http协议访问harbor" class="headerlink" title="使用http协议访问harbor"></a>使用http协议访问harbor</h5><p>harbor默认使用https协议，如果不想使用https协议，可以修改&#x2F;etc&#x2F;docker&#x2F;daemon.json文件。</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">vim /etc/docker/daemon.json</span></span><br><span class="line">&#123;</span><br><span class="line">    &quot;registry-mirrors&quot;: [&quot;https://registry.docker-cn.com&quot;,&quot;http://hub-mirror.c.163.com&quot;],</span><br><span class="line">    &quot;insecure-registries&quot;: [&quot;10.138.3.111:80&quot;]</span><br><span class="line">&#125;</span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">将harbor主机IP地址(如果配置了域名解析可直接使用域名)和端口写入该文件，让其受信任即可</span></span><br></pre></td></tr></table></figure>

<p> 注释掉harbor.yml.tmpl文件中关于https的内容</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">vim harbor.yml.tmpl  <span class="comment"># 注释掉该文件中下面的内容</span></span></span><br><span class="line">https:            </span><br><span class="line">  port: 443    </span><br><span class="line">  certificate: /your/certificate/path</span><br><span class="line">  private_key: /your/private/key/path</span><br></pre></td></tr></table></figure>

<h5 id="使用https协议访问harbor"><a href="#使用https协议访问harbor" class="headerlink" title="使用https协议访问harbor"></a>使用https协议访问harbor</h5><p>使用https协议需要证书，接下来我们使用cfssl进行自签证书。</p>
<p>安装cfssl</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">wget https://pkg.cfssl.org/R1.2/cfssl_linux-amd64</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">wget https://pkg.cfssl.org/R1.2/cfssljson_linux-amd64</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">wget https://pkg.cfssl.org/R1.2/cfssl-certinfo_linux-amd64</span></span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">添加执行权限</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash"><span class="built_in">chmod</span> +x cfssl_linux-amd64 cfssljson_linux-amd64 cfssl-certinfo_linux-amd64</span></span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">移动至环境变量路径</span></span><br><span class="line">mv cfssl_linux-amd64 /usr/local/bin/cfssl   # 生成证书工具</span><br><span class="line">mv cfssljson_linux-amd64 /usr/local/bin/cfssljson</span><br><span class="line">mv cfssl-certinfo_linux-amd64 /usr/local/bin/cfssl-certinfo  # 证书信息查看工具</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">验证</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">cfssl version</span></span><br><span class="line">Version: 1.2.0</span><br><span class="line">Revision: dev</span><br><span class="line">Runtime: go1.6</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">生成ca证书配置文件</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash"><span class="built_in">mkdir</span> ssl</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash"><span class="built_in">cd</span> ssl &amp;&amp; cfssl print-defaults config &gt; ca-config.json</span>  </span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash"><span class="built_in">cat</span> ca-config.json</span></span><br><span class="line">&#123;</span><br><span class="line">    &quot;signing&quot;: &#123;</span><br><span class="line">        &quot;default&quot;: &#123;</span><br><span class="line">            &quot;expiry&quot;: &quot;168h&quot;   # 过期时间，默认为168h，此处修改成87600h=10年</span><br><span class="line">        &#125;,</span><br><span class="line">        &quot;profiles&quot;: &#123;</span><br><span class="line">            &quot;www&quot;: &#123;</span><br><span class="line">                &quot;expiry&quot;: &quot;87600h&quot;,  # 默认是1年，这里修改成10年</span><br><span class="line">                &quot;usages&quot;: [</span><br><span class="line">                    &quot;signing&quot;,</span><br><span class="line">                    &quot;key encipherment&quot;,</span><br><span class="line">                    &quot;server auth&quot;</span><br><span class="line">                ]</span><br><span class="line">            &#125;,</span><br><span class="line">            &quot;client&quot;: &#123;</span><br><span class="line">                &quot;expiry&quot;: &quot;87600h&quot;,  # 默认是1年，这里修改成10年</span><br><span class="line">                &quot;usages&quot;: [</span><br><span class="line">                    &quot;signing&quot;,</span><br><span class="line">                    &quot;key encipherment&quot;,</span><br><span class="line">                    &quot;client auth&quot;</span><br><span class="line">                ]</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">生成ca证书信息文件</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">cfssl print-defaults csr &gt; ca-csr.json</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash"><span class="built_in">cat</span> ca-csr.json</span> </span><br><span class="line">&#123;</span><br><span class="line">    &quot;CN&quot;: &quot;example.net&quot;,   # 标识具体的域</span><br><span class="line">    &quot;hosts&quot;: [            # 使用该证书的域名</span><br><span class="line">        &quot;example.net&quot;,</span><br><span class="line">        &quot;www.example.net&quot;</span><br><span class="line">    ],</span><br><span class="line">    &quot;key&quot;: &#123;    # 加密方式，一般使用rsa，大小使用2048</span><br><span class="line">        &quot;algo&quot;: &quot;ecdsa&quot;,  # 加密方式，默认是ecdsa，此处使用rsa</span><br><span class="line">        &quot;size&quot;: 256       # 默认是256，此处使用2048</span><br><span class="line">    &#125;,</span><br><span class="line">    &quot;names&quot;: [            # 证书中包含的国家地区和城市信息</span><br><span class="line">        &#123;</span><br><span class="line">            &quot;C&quot;: &quot;US&quot;,   # 表示国家，修改成CN</span><br><span class="line">            &quot;L&quot;: &quot;CA&quot;,   # 区域，这里修改成SiChuan</span><br><span class="line">            &quot;ST&quot;: &quot;San Francisco&quot;   # 城市，修改成本地国内城市，ChengDu</span><br><span class="line">        &#125;</span><br><span class="line">    ]</span><br><span class="line">&#125;</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">使用证书信息文件生成证书</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">cfssl gencert -initca ca-csr.json | cfssljson -bare ca -</span></span><br><span class="line">2021/04/05 13:07:11 [INFO] generating a new CA key and certificate from CSR</span><br><span class="line">2021/04/05 13:07:11 [INFO] generate received request</span><br><span class="line">2021/04/05 13:07:11 [INFO] received CSR</span><br><span class="line">2021/04/05 13:07:11 [INFO] generating key: rsa-2048</span><br><span class="line">2021/04/05 13:07:12 [INFO] encoded CSR</span><br><span class="line">2021/04/05 13:07:12 [INFO] signed certificate with serial number 697269161568410809548825101035635405041110584154</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">执行完成后，将生成两个pem文件，如下</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash"><span class="built_in">ls</span> *.pem</span></span><br><span class="line">ca-key.pem  ca.pem</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">签署服务端证书</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash"><span class="built_in">cp</span> ca-csr.json reg.com-csr.json</span> </span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">vim reg.com-csr.json</span></span><br><span class="line">&#123;</span><br><span class="line">    &quot;CN&quot;: &quot;reg.com&quot;,   # 跟harbor配置文件中的域名一致</span><br><span class="line">    &quot;hosts&quot;: [],</span><br><span class="line">    &quot;key&quot;: &#123;    # 加密方式</span><br><span class="line">        &quot;algo&quot;: &quot;rsa&quot;,  </span><br><span class="line">        &quot;size&quot;: 2048       </span><br><span class="line">    &#125;,</span><br><span class="line">    &quot;names&quot;: [            # 证书中包含的国家地区和城市信息</span><br><span class="line">        &#123;</span><br><span class="line">            &quot;C&quot;: &quot;CN&quot;,   # 国家</span><br><span class="line">            &quot;L&quot;: &quot;SiChuan&quot;,   # 区域</span><br><span class="line">            &quot;ST&quot;: &quot;ChengDu&quot;   # 城市</span><br><span class="line">        &#125;</span><br><span class="line">    ]</span><br><span class="line">&#125;</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">签发证书</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">cfssl gencert -ca=ca.pem -ca-key=ca-key.pem -config=ca-config.json -profile=www reg.com-csr.json | cfssljson -bare reg.com</span></span><br><span class="line">2021/04/05 13:07:56 [INFO] generate received request</span><br><span class="line">2021/04/05 13:07:56 [INFO] received CSR</span><br><span class="line">2021/04/05 13:07:56 [INFO] generating key: rsa-2048</span><br><span class="line">2021/04/05 13:07:56 [INFO] encoded CSR</span><br><span class="line">2021/04/05 13:07:56 [INFO] signed certificate with serial number 184797551865598110499745729080826042064714656658</span><br><span class="line">2021/04/05 13:07:56 [WARNING] This certificate lacks a &quot;hosts&quot; field. This makes it unsuitable for</span><br><span class="line">websites. For more information see the Baseline Requirements for the Issuance and Management</span><br><span class="line">of Publicly-Trusted Certificates, v.1.1.6, from the CA/Browser Forum (https://cabforum.org);</span><br><span class="line">specifically, section 10.2.3 (&quot;Information Requirements&quot;).</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash"><span class="built_in">ls</span> *.pem</span></span><br><span class="line">ca-key.pem  ca.pem  reg.com-key.pem  reg.com.pem</span><br></pre></td></tr></table></figure>

<p>修改harbor配置文件，将证书路径写入harbor配置文件中</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash"><span class="built_in">ls</span> /etc/docker/ssl</span></span><br><span class="line">reg.com-key.pem  reg.com.pem</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">vim harbor.yml.tmpl    <span class="comment"># 将路径写入即可</span></span></span><br><span class="line">···</span><br><span class="line">http</span><br><span class="line">  port: 80    # 注释掉关于http的信息</span><br><span class="line">https:</span><br><span class="line">  port: 443</span><br><span class="line">  certificate: /etc/docker/ssl/reg.com.pem</span><br><span class="line">  private_key: /etc/docker/ssl/reg.com-key.pem</span><br><span class="line">···</span><br></pre></td></tr></table></figure>

<h5 id="安装"><a href="#安装" class="headerlink" title="安装"></a>安装</h5><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">准备配置文件</span></span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash"><span class="built_in">cd</span> /root/harbor &amp;&amp; <span class="built_in">mv</span> harbor.yml.tmpl harbor.yml</span> </span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">docker image load -i harbor.v2.2.1.tar.gz &amp;&amp; ./prepare</span>   </span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">安装并启动harbor容器</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">./install.sh</span></span><br><span class="line">····</span><br><span class="line">Creating network &quot;harbor_harbor&quot; with the default driver</span><br><span class="line">Creating harbor-log ... done</span><br><span class="line">Creating harbor-db     ... done</span><br><span class="line">Creating registry      ... done</span><br><span class="line">Creating harbor-portal ... done</span><br><span class="line">Creating redis         ... done</span><br><span class="line">Creating registryctl   ... done</span><br><span class="line">Creating harbor-core   ... done</span><br><span class="line">Creating nginx             ... done</span><br><span class="line">Creating harbor-jobservice ... done</span><br><span class="line">✔ ----Harbor has been installed and started successfully.----  #</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">docker contianer <span class="built_in">ls</span></span> </span><br></pre></td></tr></table></figure>

<p><img src="/pic/docker-pic/1111111.png" alt="image-20210405140323830"></p>
<h3 id="访问web页面"><a href="#访问web页面" class="headerlink" title="访问web页面"></a>访问web页面</h3><p>将reg.com域名解析写入windows主机中的hosts文件，做完域名解析后在web浏览器中输入域名，由于我们使用的是自签证书，因此还是会提示链接不安全(并显示在浏览器uri前面)，点击”添加另外”即可：</p>
<p><img src="/pic/docker-pic/image-20221024185454889.png" alt="image-20221024185454889"></p>
<p>登陆界面如下，用户名admin，密码为harbor.yml文件中定义的admin密码：</p>
<p><img src="/pic/docker-pic/image-20221024185659474.png" alt="image-20221024185659474"></p>
<p>进入控制台，不喜欢该主题的话，可以点击下方<code>浅色主题</code>进行切换</p>
<p><img src="/pic/docker-pic/image-20221024185740543.png" alt="image-20221024185740543"></p>
<p>查看证书方法</p>
<img src="/pic/docker-pic/image-20221024185823663.png" alt="image-20221024185823663" style="zoom:67%;" />

<p>证书信息：</p>
<img src="/pic/docker-pic/image-20221024185846756.png" alt="image-20221024185846756" style="zoom:67%;" />

<h3 id="harbor仓库的使用"><a href="#harbor仓库的使用" class="headerlink" title="harbor仓库的使用"></a>harbor仓库的使用</h3><h4 id="命令行登陆到harbor仓库"><a href="#命令行登陆到harbor仓库" class="headerlink" title="命令行登陆到harbor仓库"></a>命令行登陆到harbor仓库</h4><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">从另外的主机访问harbor仓库</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">docker login https://reg.com</span></span><br><span class="line">Username: admin</span><br><span class="line">Password: </span><br><span class="line">Error response from daemon: login attempt to https://reg.com/v2/ failed with status: 404 Not Found</span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">提示找不到https://reg.com，解决方法做hosts域名解析</span></span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash"><span class="built_in">echo</span> <span class="string">&quot;10.138.3.111 reg.com&quot;</span> &gt;&gt; /etc/hosts</span></span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">做完hosts域名解析后，再一次登陆，提示未知的认证</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">docker login https://reg.com</span></span><br><span class="line">Username: admin</span><br><span class="line">Password: </span><br><span class="line">Error response from daemon: Get https://reg.com/v2/: x509: certificate signed by unknown authority</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">此时查看harbor主机上的messages日志，将看到访问失败的信息</span></span><br><span class="line">Apr  5 15:20:13 reg dockerd: time=&quot;2021-04-05T15:20:13.964537621+08:00&quot; level=error msg=&quot;Handler for POST /v1.41/auth returned error: login attempt to https://reg.com/v2/ failed with status: 404 Not Found&quot;</span><br><span class="line">Apr  5 15:24:35 reg dockerd: time=&quot;2021-04-05T15:24:35.416729925+08:00&quot; level=info msg=&quot;Error logging in to endpoint, trying next endpoint&quot; error=&quot;Get https://reg.com/v2/: x509: certificate signed by unknown authority&quot;</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">解决方法，将harbor主机上的自签证书拷贝到需要访问harbor的主机上</span></span><br><span class="line">mkdir /etc/docker/certs.d/reg.com -p  # 在被访问主机上新建目录，目录名称是/etc/docker/certs.d/harbor主机域名</span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">将harbor主机上的reg.com.pem文件拷贝到被访问主机上，名称后缀为.crt，不是.pem</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">scp -P 10022 /etc/docker/ssl/reg.com.pem 10.138.3.111:/etc/docker/certs.d/reg.com/reg.com.crt</span></span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">再次访问就没有问题了</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">docker login https://reg.com</span></span><br><span class="line">Username: admin</span><br><span class="line">Password: </span><br><span class="line">WARNING! Your password will be stored unencrypted in /root/.docker/config.json.</span><br><span class="line">Configure a credential helper to remove this warning. See</span><br><span class="line">https://docs.docker.com/engine/reference/commandline/login/#credentials-store</span><br><span class="line"></span><br><span class="line">Login Succeeded</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">查看主机上所有镜像</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">docker image <span class="built_in">ls</span></span></span><br><span class="line">REPOSITORY   TAG                 IMAGE ID       CREATED        SIZE</span><br><span class="line">php          lnmp_php_7.4.16     960a00c2710a   6 hours ago    712MB</span><br><span class="line">nginx        lnmp_ningx_1.18.0   438f02d48ea9   15 hours ago   489MB</span><br><span class="line">mysql        5.7                 cd0f0b1e283d   5 days ago     449MB</span><br><span class="line">centos       centos7.6.1810      f1cb7c7d58b7   2 years ago    202MB</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">给centos镜像修改标签</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">docker tag centos:centos7.6.1810 reg.com/library/centos:centos7.6.1810</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">docker image <span class="built_in">ls</span></span></span><br><span class="line">REPOSITORY               TAG                 IMAGE ID       CREATED        SIZE</span><br><span class="line">php                      lnmp_php_7.4.16     960a00c2710a   6 hours ago    712MB</span><br><span class="line">nginx                    lnmp_ningx_1.18.0   438f02d48ea9   15 hours ago   489MB</span><br><span class="line">mysql                    5.7                 cd0f0b1e283d   5 days ago     449MB</span><br><span class="line">centos                   centos7.6.1810      f1cb7c7d58b7   2 years ago    202MB</span><br><span class="line">reg.com/library/centos   centos7.6.1810      f1cb7c7d58b7   2 years ago    202MB</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">推送centos镜像到reg.com仓库中</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">docker push reg.com/library/centos:centos7.6.1810</span></span><br><span class="line">The push refers to repository [reg.com/library/centos]</span><br><span class="line">89169d87dbe2: Pushed </span><br><span class="line">centos7.6.1810: digest: sha256:747b2de199b6197a26eb1a24d69740d25483995842b2d2f75824095e9d1d19eb size: 529</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h4 id="推送镜像到harbor仓库"><a href="#推送镜像到harbor仓库" class="headerlink" title="推送镜像到harbor仓库"></a>推送镜像到harbor仓库</h4><p>harbor仓库中给出的镜像推送方法提示：</p>
<p><img src="/pic/docker-pic/image-20221024190002764.png" alt="image-20221024190002764"></p>
<p>镜像推送完成后，我们刷新页面，查看harbor页面上的镜像信息：</p>
<p><img src="/pic/docker-pic/image-20221024190024099.png" alt="image-20221024190024099"></p>
<h4 id="harbor集群"><a href="#harbor集群" class="headerlink" title="harbor集群"></a>harbor集群</h4><p><img src="/pic/docker-pic/image-20210405155317751.png" alt="image-20210405155317751"></p>
<p>通过前文的方法，配置多台harbor主机，此处使用http协议进行访问，具体方法不再赘述。</p>
<p>安装完成后，登陆备库</p>
<p><img src="/pic/docker-pic/image-20210407093120139.png" alt="image-20210407093120139"></p>
<p>登陆主库进行主备配置，点击<code>仓库管理</code>–&gt;<code>新建目标</code>，填入备库的访问地址，输入备库的访问用户和密码，如图所示：</p>
<p><img src="/pic/docker-pic/image-20210407093838402.png" alt="image-20210407093838402"></p>
<p>测试连接：</p>
<p><img src="/pic/docker-pic/image-20210407094451578.png" alt="image-20210407094451578"></p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">进入harbor安装目录，执行命令，停止harbor镜像仓库</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">docker-compose  down</span> </span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">vim /etc/docker/daemon.json</span> </span><br><span class="line">&#123;</span><br><span class="line">    &quot;registry-mirrors&quot;: [&quot;https://registry.docker-cn.com&quot;,&quot;http://hub-mirror.c.163.com&quot;],</span><br><span class="line">    &quot;insecure-registries&quot;: [&quot;10.138.3.222:80&quot;]  # 将被控端域名添加信任</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>完成后，如下：</p>
<p><img src="/pic/docker-pic/image-20210407093246786.png" alt="image-20210407093246786"></p>
<p>新建复制规则：</p>
<p><img src="/pic/docker-pic/image-20210407101521855.png" alt="image-20210407101521855"></p>
<p>创建完成后，如下：</p>
<p><img src="/pic/docker-pic/image-20210407100135332.png" alt="image-20210407100135332"></p>
<p>现在，我们推送一个镜像到<code>reg.com</code>主库中，查看备库<code>10.138.3.222:80</code>是否进行了同步</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">docker tag mysql:5.7 reg.com/library/mysql:5.7</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">docker image <span class="built_in">ls</span> | grep mysql</span> </span><br><span class="line">mysql                           5.7                 cd0f0b1e283d   6 days ago    449MB</span><br><span class="line">reg.com/library/mysql           5.7                 cd0f0b1e283d   6 days ago    449MB</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">docker login reg.com   <span class="comment"># 登陆主库</span></span></span><br><span class="line">Authenticating with existing credentials...</span><br><span class="line">WARNING! Your password will be stored unencrypted in /root/.docker/config.json.</span><br><span class="line">Configure a credential helper to remove this warning. See</span><br><span class="line">https://docs.docker.com/engine/reference/commandline/login/#credentials-store</span><br><span class="line"></span><br><span class="line">Login Succeeded</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">推送镜像到主库</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">docker push reg.com/library/mysql:5.7</span>   </span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p>查看<code>reg.com</code>主库，检查是否推送成功</p>
<p><img src="/pic/docker-pic/image-20210407102231326.png" alt="image-20210407102231326"></p>
<p>查看<code>reg.com</code>上<code>复制管理</code>中的信息，显示复制成功</p>
<p><img src="/pic/docker-pic/image-20210407102333046.png" alt="image-20210407102333046"></p>
<p>检查备库<code>10.138.3.222:80</code>是否成功同步了<code>msyql:5.7</code></p>
<p><img src="/pic/docker-pic/image-20210407102436663.png" alt="image-20210407102436663"></p>
<p>同步成功</p>
<p>配置主主</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash"><span class="built_in">mkdir</span> /etc/docker/certs.d/reg.com -p    <span class="comment"># 在备服务器上新建目录</span></span></span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">将reg.com主机上的认证文件拷贝到备服务器上</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">scp -P 10022 /etc/docker/ssl/reg.com.pem 10.138.3.222:/etc/docker/certs.d/reg.com/reg.com.crt</span></span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">查看备服务器上的认证文件</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash"><span class="built_in">ls</span> /etc/docker/certs.d/reg.com/reg.com.crt</span> </span><br><span class="line">/etc/docker/certs.d/reg.com/reg.com.crt</span><br></pre></td></tr></table></figure>

<p>主从复制+备份harbor数据目录&#x2F;data&#x2F;+数据库文件</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">日志文件</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash"><span class="built_in">ls</span> /var/log/harbor/</span></span><br><span class="line">core.log  jobservice.log  portal.log  postgresql.log  proxy.log  redis.log  registryctl.log  registry.log</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">harbor数据文件</span></span><br><span class="line">ls /data/</span><br><span class="line">ca_download  database  job_logs  redis  registry  secret</span><br><span class="line"></span><br><span class="line">ls /data/registry/docker/registry/v2/repositories/library/centos/</span><br><span class="line">_layers  _manifests  _uploads  # library/centos是我们刚刚上传的centos镜像</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash"><span class="built_in">ls</span> /data/secret/</span></span><br><span class="line">cert  core  keys  registry</span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash"><span class="built_in">ls</span> /data/secret/core/</span></span><br><span class="line">private_key.pem</span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash"><span class="built_in">ls</span> /data/secret/cert/</span></span><br><span class="line">server.crt  server.key</span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash"><span class="built_in">ls</span> /data/secret/keys/</span></span><br><span class="line">secretkey</span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash"><span class="built_in">ls</span> /data/secret/registry/</span></span><br><span class="line">root.crt</span><br></pre></td></tr></table></figure>

<h4 id="忘记harbor登陆密码的解决方法"><a href="#忘记harbor登陆密码的解决方法" class="headerlink" title="忘记harbor登陆密码的解决方法"></a>忘记harbor登陆密码的解决方法</h4><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash"><span class="built_in">echo</span> -n <span class="string">&quot;Admin@2020&quot;</span>|<span class="built_in">md5sum</span></span></span><br><span class="line">06d1108043ad13aebdca098c7e6bfe64  -</span><br><span class="line"></span><br><span class="line">[root@reg ~]# docker exec -it harbor-db /bin/bash   # 进入数据库容器  </span><br><span class="line">postgres [ / ]$ netstat  -lntp </span><br><span class="line">Active Internet connections (only servers)</span><br><span class="line">Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name</span><br><span class="line">tcp        0      0 0.0.0.0:5432            0.0.0.0:*               LISTEN      1/postgres      </span><br><span class="line">tcp        0      0 127.0.0.11:34651        0.0.0.0:*               LISTEN      -               </span><br><span class="line">tcp6       0      0 :::5432                 :::*                    LISTEN      1/postgres </span><br><span class="line"></span><br><span class="line">postgres [ / ]$  psql -U postgres -d postgres -h 127.0.0.1 -p 5432   # 登陆数据库</span><br><span class="line">psql (9.6.21)</span><br><span class="line">Type &quot;help&quot; for help.</span><br><span class="line"></span><br><span class="line">postgres=# help</span><br><span class="line">You are using psql, the command-line interface to PostgreSQL.</span><br><span class="line">Type:  \copyright for distribution terms</span><br><span class="line">       \h for help with SQL commands</span><br><span class="line">       \? for help with psql commands</span><br><span class="line">       \g or terminate with semicolon to execute query</span><br><span class="line">       \q to quit</span><br><span class="line">postgres=# \c registry    # 切换到registry数据库中</span><br><span class="line">You are now connected to database &quot;registry&quot; as user &quot;postgres&quot;.</span><br><span class="line"></span><br><span class="line">registry=# select * from harbor_user;</span><br><span class="line"> user_id | username |           password                |realname       |             salt            |</span><br><span class="line">---------+-----------+---------------------------------+----------------+-----------------------------+</span><br><span class="line">       2 | anonymous |                                 | anonymous user |                             | </span><br><span class="line">       1 | admin     |b5361d73851310e3f99e417c21f00fff | system admin  |F9xavf065XBc44obZewfrSrVkUoF42Gd </span><br><span class="line">(2 rows)</span><br></pre></td></tr></table></figure>

</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="https://rushiy.gitee.io">rushiy</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="https://rushiy.gitee.io/docker/docker%E9%95%9C%E5%83%8F%E4%BB%93%E5%BA%93/">https://rushiy.gitee.io/docker/docker%E9%95%9C%E5%83%8F%E4%BB%93%E5%BA%93/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="https://rushiy.gitee.io" target="_blank">如是的学习博客</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/tags/docker/">docker</a></div><div class="post_share"><div class="social-share" data-image="" data-sites="wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/js/social-share.min.js" defer></script></div></div></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src="/img/favicon.jpg" onerror="this.onerror=null;this.src='/img/friend_404.gif'" alt="avatar"/></div><div class="author-info__name">rushiy</div><div class="author-info__description"></div></div><div class="card-info-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">28</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">3</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">0</div></a></div><div class="card-info-social-icons is-center"><a class="social-icon" href="mailto:rushiy@reg.email.cn" target="_blank" title="Email"><i class="fas fa-envelope"></i></a></div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span><span class="toc-percentage"></span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#docker%E9%95%9C%E5%83%8F%E4%BB%93%E5%BA%93"><span class="toc-number">1.</span> <span class="toc-text">docker镜像仓库</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%88%B6%E4%BD%9C%E6%9C%AC%E5%9C%B0%E9%95%9C%E5%83%8F%E4%BB%93%E5%BA%93"><span class="toc-number">1.1.</span> <span class="toc-text">制作本地镜像仓库</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%9C%AC%E5%9C%B0%E9%95%9C%E5%83%8F%E4%BB%93%E5%BA%93%E5%8A%A0%E5%AF%86"><span class="toc-number">1.2.</span> <span class="toc-text">本地镜像仓库加密</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E7%A7%81%E6%9C%89%E4%BB%93%E5%BA%93harbor"><span class="toc-number">2.</span> <span class="toc-text">私有仓库harbor</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#harbor%E7%AE%80%E4%BB%8B"><span class="toc-number">2.1.</span> <span class="toc-text">harbor简介</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#harbor%E7%BB%84%E4%BB%B6%EF%BC%9A"><span class="toc-number">2.2.</span> <span class="toc-text">harbor组件：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#harbor%E4%B8%8B%E8%BD%BD%E4%B8%8E%E5%AE%89%E8%A3%85"><span class="toc-number">2.3.</span> <span class="toc-text">harbor下载与安装</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#harbor%E4%B8%8B%E8%BD%BD"><span class="toc-number">2.3.1.</span> <span class="toc-text">harbor下载</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%AE%89%E8%A3%85%E6%96%B9%E5%BC%8F"><span class="toc-number">2.3.2.</span> <span class="toc-text">安装方式</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#harbor%E5%AE%89%E8%A3%85"><span class="toc-number">2.4.</span> <span class="toc-text">harbor安装</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%AE%89%E8%A3%85docker"><span class="toc-number">2.4.1.</span> <span class="toc-text">安装docker</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%AE%89%E8%A3%85docker-compose"><span class="toc-number">2.4.2.</span> <span class="toc-text">安装docker-compose</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%AE%89%E8%A3%85harbor"><span class="toc-number">2.4.3.</span> <span class="toc-text">安装harbor</span></a><ol class="toc-child"><li class="toc-item toc-level-5"><a class="toc-link" href="#%E8%A7%A3%E5%8E%8B%E5%B9%B6%E8%AE%A4%E8%AF%86harbor%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6"><span class="toc-number">2.4.3.1.</span> <span class="toc-text">解压并认识harbor配置文件</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#%E4%BD%BF%E7%94%A8http%E5%8D%8F%E8%AE%AE%E8%AE%BF%E9%97%AEharbor"><span class="toc-number">2.4.3.2.</span> <span class="toc-text">使用http协议访问harbor</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#%E4%BD%BF%E7%94%A8https%E5%8D%8F%E8%AE%AE%E8%AE%BF%E9%97%AEharbor"><span class="toc-number">2.4.3.3.</span> <span class="toc-text">使用https协议访问harbor</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#%E5%AE%89%E8%A3%85"><span class="toc-number">2.4.3.4.</span> <span class="toc-text">安装</span></a></li></ol></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E8%AE%BF%E9%97%AEweb%E9%A1%B5%E9%9D%A2"><span class="toc-number">2.5.</span> <span class="toc-text">访问web页面</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#harbor%E4%BB%93%E5%BA%93%E7%9A%84%E4%BD%BF%E7%94%A8"><span class="toc-number">2.6.</span> <span class="toc-text">harbor仓库的使用</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%91%BD%E4%BB%A4%E8%A1%8C%E7%99%BB%E9%99%86%E5%88%B0harbor%E4%BB%93%E5%BA%93"><span class="toc-number">2.6.1.</span> <span class="toc-text">命令行登陆到harbor仓库</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E6%8E%A8%E9%80%81%E9%95%9C%E5%83%8F%E5%88%B0harbor%E4%BB%93%E5%BA%93"><span class="toc-number">2.6.2.</span> <span class="toc-text">推送镜像到harbor仓库</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#harbor%E9%9B%86%E7%BE%A4"><span class="toc-number">2.6.3.</span> <span class="toc-text">harbor集群</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%BF%98%E8%AE%B0harbor%E7%99%BB%E9%99%86%E5%AF%86%E7%A0%81%E7%9A%84%E8%A7%A3%E5%86%B3%E6%96%B9%E6%B3%95"><span class="toc-number">2.6.4.</span> <span class="toc-text">忘记harbor登陆密码的解决方法</span></a></li></ol></li></ol></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/django/Django%E6%A8%A1%E6%9D%BF%E7%B3%BB%E7%BB%9F/" title="Django模板系统"><img src="" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="Django模板系统"/></a><div class="content"><a class="title" href="/django/Django%E6%A8%A1%E6%9D%BF%E7%B3%BB%E7%BB%9F/" title="Django模板系统">Django模板系统</a><time datetime="2022-11-04T07:08:03.000Z" title="发表于 2022-11-04 15:08:03">2022-11-04</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/django/Django%E8%A7%86%E5%9B%BE/" title="Django视图"><img src="" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="Django视图"/></a><div class="content"><a class="title" href="/django/Django%E8%A7%86%E5%9B%BE/" title="Django视图">Django视图</a><time datetime="2022-11-03T07:07:51.000Z" title="发表于 2022-11-03 15:07:51">2022-11-03</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/django/Django%E8%B7%AF%E7%94%B1%E7%B3%BB%E7%BB%9F/" title="Django路由系统"><img src="" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="Django路由系统"/></a><div class="content"><a class="title" href="/django/Django%E8%B7%AF%E7%94%B1%E7%B3%BB%E7%BB%9F/" title="Django路由系统">Django路由系统</a><time datetime="2022-11-02T07:07:34.000Z" title="发表于 2022-11-02 15:07:34">2022-11-02</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/django/%E8%B5%B0%E8%BF%9BDjango/" title="走进Django"><img src="" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="走进Django"/></a><div class="content"><a class="title" href="/django/%E8%B5%B0%E8%BF%9BDjango/" title="走进Django">走进Django</a><time datetime="2022-11-01T07:01:20.000Z" title="发表于 2022-11-01 15:01:20">2022-11-01</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/python/python%E5%B8%B8%E7%94%A8%E6%A8%A1%E5%9D%97/" title="python常用模块"><img src="" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="python常用模块"/></a><div class="content"><a class="title" href="/python/python%E5%B8%B8%E7%94%A8%E6%A8%A1%E5%9D%97/" title="python常用模块">python常用模块</a><time datetime="2022-10-28T15:34:07.000Z" title="发表于 2022-10-28 23:34:07">2022-10-28</time></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2022 By rushiy</div><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><button id="go-up" type="button" title="回到顶部"><i class="fas fa-arrow-up"></i></button></div></div><div><script src="/js/utils.js"></script><script src="/js/main.js"></script><script src="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.umd.min.js"></script><div class="js-pjax"></div><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/dist/activate-power-mode.min.js"></script><script>POWERMODE.colorful = true;
POWERMODE.shake = true;
POWERMODE.mobile = false;
document.body.addEventListener('input', POWERMODE);
</script><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div></body></html>